package com.aipanda.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * 产品属性类|memo[产品属性值是可选的,如果产品属性有多选值,应该都放在属性类]<br/>
 * ---商品管理->商品属性->可选项
 * @param name 				属性名称
 * @param propertyIndex 	属性索引
 * @param productCategory  	产品分类   	[多对一关系]
 * @param options  			属性可选项  	[一对多关系]
 * @author wanyuxiang
 *
 */
@Entity
@Table(name = "aipanda_attribute")
public class Attribute extends OrderEntity {
	private static final long serialVersionUID = 2447794131117928367L;
	private String name;
	private Integer propertyIndex;
	private ProductCategory productCategory;
	private List<String> options = new ArrayList<String>();

	@JsonProperty
	@NotEmpty
	@Length(max = 255)
	@Column(nullable = false)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name="property_index",nullable = false, updatable = false)
	public Integer getPropertyIndex() {
		return this.propertyIndex;
	}

	public void setPropertyIndex(Integer propertyIndex) {
		this.propertyIndex = propertyIndex;
	}

	@NotNull(groups = { BaseEntity.Save.class })
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="product_category",nullable = false, updatable = false)
	public ProductCategory getProductCategory() {
		return this.productCategory;
	}

	public void setProductCategory(ProductCategory productCategory) {
		this.productCategory = productCategory;
	}

	@JsonProperty
	@NotEmpty
	@ElementCollection
	@CollectionTable(name = "aipanda_attribute_option",joinColumns = {@JoinColumn(name="attribute")})
	@Column(name="options")
	public List<String> getOptions() {
		return this.options;
	}

	public void setOptions(List<String> options) {
		this.options = options;
	}
}
